package Function;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Vector;

import Function.Utils.FCFileCopyToMaterial;
import VWorldGameStudio.FCAction;
import VWorldGameStudio.FCAnimation;
import VWorldGameStudio.FCMonster;
import com.google.gson.Gson;
import utils.FCDataSingles;

public class FCMonsterLibrary {
	private Vector<FCMonster> monsterlist = new Vector<FCMonster>();
	public Vector<String> monstername = new Vector<String>();
	private FCFileCopyToMaterial filecopy = new FCFileCopyToMaterial();
	private static final String MONSTER_LIST_PATH = "./data/monsterlist.vw";
	private static final String MONSTERS_PATH = "./data/monster";
	private int monsterallnum=0;
	/**
	 * 初始化怪物类，读取数量
	 * 建议游戏启动方使用
	 * @date 2021-11-30
	 */
	public FCMonsterLibrary() {
		try {
			this.monsterallnum=new File(MONSTERS_PATH).listFiles().length;
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 怪物数据加载函数
	 * @date 2021-11-30
	 */ 
	public void loadMonsterData() {
		try {
			Gson gson = new Gson();
			File[] f=new File(MONSTERS_PATH).listFiles();
			for(int i=0;i<monsterallnum;i++) {
				FCMonster monster = FCDataSingles.getReader().readMonsterData(i,f[i].getPath());
				monstername.add(monster.getName());
				monsterlist.add(monster);
				System.out.println("==>"+gson.toJson(monster));
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 获取怪物实际数据量
	 * @return integer
	 * @date 2021-11-30
	 */
	public int getMonsterAllNum() {
		return this.monsterallnum;
	}
//	/**
//	 * 初始化怪物
//	 *
//	 * @param isGame
//	 */
//	public FCMonsterLibrary(boolean isGame) {
//		try {
//			File[] f = new File(MONSTERS_PATH).listFiles();
//			int i = 0;
//			for(File file: f){
//				FCMonster monster = FCDataSingles.getReader().readMonsterData(i, file.getAbsolutePath());
//				if(monster != null) {
//					monstername.add(monster.getName());
//					monsterlist.add(monster);
//				}
//				i++;
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}

	// 注册怪物
//	public void registerMonster(boolean isnew, int ID, String name, String type, int money, int blood, int defense,
//			double dodge, int bloodAdd, int experience, int gun1Defense,  int gun1HurtOfCharacter,
//			int gun1HurtOfTank, int gun1destruction, int gun1desdenfese, int gun2Defense,
//			int gun2HurtOfCharacter, int gun2HurtOfTank, int gun2destruction, int gun2desdenfese,
//			int gun3HurtOfCharacter, int gun3HurtOfTank, int gun3destruction, int gun3desdenfese, double resistance1,
//			double resistance2, double resistance3, double resistance4, double resistance5, int speed, int eventID,
//			String gun1ActionID, String gun2ActionID, String gun3ActionID, String dropItemID, double dropPro,
//			String pngurl,double fireresistance, String upgraedTarget, String keepTank, ArrayList<String> items) {
////		FCMonster m = new FCMonster();
////		m.registerMonster(ID, name, type, money, blood, defense, dodge, bloodAdd, experience,
////				filecopy.copyPngToMaterialPng(4, pngurl), gun1Defense, gun1HurtOfCharacter, gun1HurtOfTank,
////				gun1destruction, gun1desdenfese, gun1ActionID, gun2Defense, gun2HurtOfCharacter,
////				gun2HurtOfTank, gun2destruction, gun2desdenfese, gun2ActionID,  gun3HurtOfCharacter,
////				gun3HurtOfTank, gun3destruction, gun3desdenfese, gun3ActionID, resistance1, resistance2, resistance3,
////				resistance4, resistance5, speed, eventID, dropItemID, dropPro);
////		m.registerMonsterFix(fireresistance,upgraedTarget,keepTank,items);
////		if (isnew) {
////			monsterlist.add(m);
////			monstername.add(name);
////		} else {
////			monsterlist.remove(ID);
////			monstername.remove(ID);
////			monsterlist.add(ID, m);
////			monstername.add(ID, name);
////		}
////		FCDataSingles.getWriter().writeMonsterData(m);
//	}

	/**
	 * 获取怪物最新ID或总数
	 * 
	 * @return num
	 */
	public int getMonsterNewID() {
		return monstername.size();
	}



	// 获取怪物根据id
	public FCMonster getMonsterOfID(String name) {
		if(name == null) return null;
		if(name.equals("null")) return null;
		return monsterlist.get(monstername.indexOf(name));
	}

	/**
	 * 获取怪物name根据num
	 * 
	 * @param num
	 * @return name
	 */
	public String getMonsterNameOfNum(int num) {
		return monstername.get(num);
	}

	public String getMonsterInfoOfNum(int num) {
		FCMonster a = monsterlist.get(num);
		return a.getChName();
	}
}
